import dayjs from 'dayjs'


// const now = dayjs()
// init
const state = {
    // currentDay: now.clone()
    currentDay: Date.now()
}

// getters
const getters = {
    currentDay (state) {
        return dayjs(state.currentDay);
    }
}

//actions
const actions = {
    setCurrentDay({commit}, day) {
        commit('setCurrentDay', day)
    },
    setToDay({commit}) {
        commit('setToDay')
    },
    lastMonth({commit}) {
        commit('lastMonth')
    },
    nextMonth({commit}) {
        commit('nextMonth')
    }
}

// mutations
const mutations = {
    setCurrentDay(state, day) {
        state.currentDay = day;
    },

    setToDay(state) {
        state.currentDay = Date.now()
    },

    lastMonth(state) {
        state.currentDay = dayjs(state.currentDay).subtract(1, 'month').valueOf();
    },

    nextMonth(state) {
        state.currentDay = dayjs(state.currentDay).add(1, 'month').valueOf();
    }
}

export default {
    namespaced: true,
    state,
    // getters,
    actions,
    mutations
}